package com.wx.wxpush.controller;

import com.wx.wxpush.entiy.Cron;
import com.wx.wxpush.mapper.CornTaskMapper;
import com.wx.wxpush.util.AddressUtils;
import com.wx.wxpush.util.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
@Controller
@RequestMapping("/jobStatus")
@Api(tags="定时器取消接口")

public class CronController {
    @Autowired
    private CornTaskMapper cornTaskMapper;

    @PostMapping(value="/ipAddress")
    public ResultVO ipAddress(HttpServletRequest request) {
        //获取IP地址
        String ipAddress = AddressUtils.getIpAddr(request);
        String address=AddressUtils.getAddressByIP(ipAddress);
        return ResultVO.ok(address);
    }
    @ApiOperation(value = "早晨定时器取消接口", notes = "入参openid,moringStatus")
    @PutMapping("/setCronMoringStatus")
    public ResultVO setCronMoringStatus(@RequestBody Cron cron){
        cornTaskMapper.updateStatus(cron.getMoringStatus(),cron.getOpenid());
        return ResultVO.ok();
    }

    @ApiOperation(value = "晚上定时器取消接口", notes = "入参openid,nightStatus")
    @PutMapping("/setCronNightStatus")
    public ResultVO setCronNightStatus(@RequestBody Cron cron){
        cornTaskMapper.updateNightStatus(cron.getOpenid(),cron.getNightStatus());
        return ResultVO.ok();
    }



}
